package com.atguigu.dwm.common.controller;

import com.atguigu.dwm.common.bean.CommonCode;
import com.atguigu.dwm.common.bean.Result;
import com.atguigu.dwm.common.service.CommonCodeService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 标准编码 前端控制器
 * </p>
 *
 * @author zhangchen
 * @since 2024-07-02
 */
@RestController
@RequestMapping("/data-common/code")
public class CommonCodeController {

    @Autowired
    CommonCodeService commonCodeService;

    @GetMapping("/options")
    public Result  getOptions(@RequestParam("pCode") String parentCode){
        QueryWrapper<CommonCode> queryWrapper = new QueryWrapper<CommonCode>()
                .select("code_no as id","code_name as name","ext_name as extName")
                .eq("parent_code_no",parentCode).eq("is_deleted","0");

        List<Map<String, Object>> mapList = commonCodeService.listMaps(queryWrapper);

        return Result.ok(mapList);
    }

}
